layui.use(['element', 'layer', 'util', 'form', 'table', 'tree'], function(){
	//注意：选项卡 依赖 element 模块，否则无法进行功能性操作
  var element = layui.element;
  var $ = layui.jquery
      , layer = layui.layer
      , element = layui.element //Tab的切换功能，切换事件监听等，需要依赖element模块
      , util = layui.util
      , table = layui.table
      , tree = layui.tree;
	  
	  
	  resetelementheight();
	  var mHeight, hheight;
	  
	  function resetelementheight() {
	      mHeight = document.documentElement.clientHeight || document.body.clientHeight;
	  
	      if (mHeight > 600) {
	          hheight = mHeight - 180;
	          $("#leftTree").css({'max-height': hheight + 'px'});
	      }
	  }
	  
	  $(window).resize(function () {
	      resetelementheight();
	      // form.render();
	  });
	  var treeDataSearch;
	  var URL = baseUrl + "dlssxx/main/dzdp/getallbridgeinfolist?fBridgeName="
	  var loading = layer.load(0, {
	      shade: false,
	      time: 2 * 1000
	  });
	  $.ajax({
	      type: "GET",
	      url: URL,
	      dataType: "json",
	      async: true,
	      success: function (result) {
			  console.log(result)
	          if (result != null || result != undefined) {
	              // layer.close(loading);
	              var treeData = result.list.map((item) => {
	                  return {
	                      title: item.fBridgeName,//节点名称
	                  }
	              })
	              treeDataSearch = treeData;//赋值给搜索
	  
	              // var clickDataID;
	              var clickDataName;
	  
	              //无连接线风格左树
	              tree.render({
	                  elem: '#leftTree'
	                  , data: treeData
	                  , showLine: false  //是否开启连接线
	                  , click: function (obj) {
	                      //layer.msg(JSON.stringify(obj.data));
	                      var loading = layer.load(0, {
	                          shade: false,
	                          time: 2 * 1000
	                      });
	                      //设置左树选中节点样式
	                      $(obj.elem[0]).siblings().css("background-color", "transparent");
	                      $(obj.elem[0]).css("background-color", "#12a9fd")
	                      // clickDataID = obj.data.id;
	                      clickDataName = obj.data.title;
						  console.log(clickDataName)
	                      refreshRight(clickDataName);
	  
	                  }
	  
	              });
	              //默认出发第一条数据
	  
	              $($('#leftTree .layui-tree-set')[0]).css("background-color", "#12a9fd");
	              // clickDataID = $($('#leftTree .layui-tree-set')[0])[0].dataset.id;
	              clickDataName = $($('#leftTree .layui-tree-set')[0])[0].innerText;
	              // refreshRight(clickDataName);
				  $('#qiaolianggname').text(clickDataName)
	          }
	  
	      },
	      // error: function (jqXHR) {
	      //     alert("发生错误：" + jqXHR.status);
	      // }
	  });
	  
	  function refreshRight(clickDataName) {
	      // refreshTable(obj1);
	      //替换道路名称
		  $('#qiaolianggname').text(clickDataName)
	      // for (var i = 0; i < $('.roadName').length; i++) {
	      //     $('#suidaoname').innerHTML = clickDataName;
	      // }
	      // refreshList(obj2);
	  }
	  
	  /**
	   * 搜索框搜索
	   */
	  var input = document.querySelector('input')
	  input.addEventListener('change', function (params) {
	      // console.log('params', params.valueOf())
	  
	      var keyWord = document.getElementsByClassName("valInput")[0].value;
	      searchFun(keyWord, treeDataSearch);
	  
	  })
	  
	  function searchFun(keyWord, list) {
	      var len = list.length;
	      var arr = [];
	      //拿到树的数据list
	  
	      for (var i = 0; i < len; i++) {
	          //如果字符串中不包含目标字符会返回-1
	          if (list[i].title.indexOf(keyWord) >= 0) {
	              arr.push(list[i]);
	          }
	  
	          //无连接线风格左树
	          tree.render({
	              elem: '#leftTree'
	              , data: arr
	              , showLine: false  //是否开启连接线
	              , click: function (obj) {
	                  //layer.msg(JSON.stringify(obj.data));
	                  var loading = layer.load(0, {
	                      shade: false,
	                      time: 2 * 1000
	                  });
	                  //设置左树选中节点样式
	                  $(obj.elem[0]).siblings().css("background-color", "transparent");
	                  $(obj.elem[0]).css("background-color", "#12a9fd")
	                  // clickDataID = obj.data.id;
	                  clickDataName = obj.data.title;
	                  refreshRight(clickDataName);
	  
	              }
	  
	          });
	      }
	      return arr;
	  }
	  
	  
	  // function refreshList(obj) {
	  
	  //     $.ajax({
	  //         type: "GET",
	  //         url: baseUrl + 'maintainjudge/main/networkingdata/getlistinfo?roadCode=' + obj,
	  //         dataType: "json",
	  //         async: true,
	  //         success: function (result) {
	  //             if (result != null || result != undefined) {
	  //                 layer.close(loading);
	  //                 tableFun(result);
	  //             } else {
	  //                 var nullHtml = '<div class="nullData">当前节点无路段明细数据</div>'
	  //                 for (var i = 0; i < $('.listTable').length; i++) {
	  //                     $('.listTable')[i].innerHTML = nullHtml;
	  //                 }
	  //             }
	  
	  //         },
	  //         error: function (jqXHR) {
	  //             alert("发生错误：" + jqXHR.status);
	  
	  //         }
	  //     });
	  
	  // }
});